﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Pub_Module_Menu : System.Web.UI.UserControl
{
    public Orientation Orien=Orientation.Vertical;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    public Orientation SetOrientation
    {
        get
        {
            return Orien;
        }
        set
        {
            Orien = value;
        }
    }

    


   protected override void AddedControl(Control control, int index)
   {
       if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1) {
           this.Page.ClientTarget = "uplevel";
       }
       base.AddedControl(control, index);
   }


    private void BindData()
    {
        mnVertical.Orientation = Orien;
        clsWebShop cls = new clsWebShop();
        DataSet ds = new DataSet();

        DataTable dtTopic = new DataTable();
        DataTable dtCat = new DataTable();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("KindNo", "P");
        ds = cls.Get_Topic_Catalogue(msg.GetXmlStr);
        dtTopic = ds.Tables[0];
        dtCat = ds.Tables[1];


        string TopicID, TopicName, CatID, CatName;
        int index = 0;
        foreach (DataRow rowTopic in dtTopic.Rows)
        {
            index++;
            MenuItem itemTopic = new MenuItem();
            bool flag = true;
            TopicID = rowTopic["TopicID"].ToString();
            TopicName = rowTopic["TopicName"].ToString();

      
            itemTopic.Text = TopicName  ;
            itemTopic.NavigateUrl = "~/Shopping/Stall/Stall.aspx?TopicID=" + TopicID;
         
         //   if (index != dtTopic.Rows.Count)
            itemTopic.SeparatorImageUrl = "~/Images/Body/line.png";



             mnVertical.Items.Add(itemTopic);

            DataRow[] rowCat;
            rowCat = dtCat.Select("TopicID=" + TopicID);
           
            for (int i = 0; i < rowCat.Length; i++)
            {
                CatID = rowCat[i]["CatID"].ToString();
                CatName = rowCat[i]["CatName"].ToString();
                MenuItem itemCat = new MenuItem();  
                


                //if (flag == false)
                //{
                //    itemCat.Text = CatName;
                //    itemCat.NavigateUrl = "~/Shopping/Stall/Stall.aspx?List=true&CatID=" + CatID;
                //}
                //else
                //{
                itemCat.Text = "<div>&nbsp;&nbsp;&nbsp;" + CatName + "</div>";
                    itemCat.NavigateUrl = "~/Shopping/Stall/Stall.aspx?CatID=" + CatID;
                //}

                itemTopic.ChildItems.Add(itemCat);
            }
        

        }
  

    }
}